<?php
	require_once 'models/models_khachhang.php';
	$mod = $_GET['mod'];
	$obkh = new models_khachhang();
	$p=new pager();//khoi tao doi tuong pager
	switch ($mod)
	{
		case 'khachhang':{
			$limit=10;
			$count=$obkh->tongsodong();
			$start=$p->findstart($limit);
			$page=$p->findpages($count,$limit);
			$data['list'] = $obkh->_listKhachHang($start,$limit);
			$pagelist=$p->pagelist($_GET['page'],$page);
			require 'views/admin/khachhang/index.php';
			break;
		}
		case 'addkhachhang':{
			if($_POST)
			{
				$obkh->_addkhachhang($_POST['tenkh'],$_POST['diachi'],$_POST['sdt']);
				echo '<script> window.location.href="admin.php?mod=khachhang"</script>';
			}
			require 'views/admin/khachhang/add.php';
			break;
		}
		case 'delkhachhang':{
			$obkh->_delKhachHang($_GET['ma']);
			echo '<script> window.location.href="admin.php?mod=khachhang"</script>';
		}
		case 'updatekhachhang':{
			if($_POST){
				$obkh->_updateKhachHang($_POST['tenkh'], $_POST['diachi'], $_POST['sdt'], $_GET['ma']);
				echo '<script>window.location.href="admin.php?mod=khachhang"</script>';
			}
			$data = $obkh->_getKhachHang($_GET['ma']);
			require 'views/admin/khachhang/edit.php';
			break;
		}
		default: echo 'khong tim thay yeu cau ';
			break;
	}
	
	
?>